/**============================================================================
 Confidential Information - Limited distribution to authorized persons only.
 This software is protected as an unpublished work under the U.S. Copyright
 Act of 1976.

 Copyright (c) 2011, BluePhoenix Solutions, Inc. All rights reserved.
 ----------------------------------------------------------------------------
 file......: DBUtils.java
 Author....: Vyacheslav Kovalyov
 Created...: 12/27/11

 Description:

 ============================================================================*/
package com.bphx.android.utils;

import android.widget.TextView;

import java.io.Closeable;
import java.util.List;

import static com.bphx.android.utils.Constants.COMMA_SEPARATOR;
import static java.lang.Integer.valueOf;
import static org.apache.commons.lang.StringUtils.EMPTY;

/**
 * @author Vyacheslav Kovalyov
 * @version 1.0
 */
public abstract class Utils {

    public static boolean isMoreThen(int num, String numberString) {

        try {
            int intNumber = valueOf(numberString);
            if (intNumber > num) {
                return true;
            }
        } catch (Exception ignored) {
        }
        return false;
    }

    public static String getTextFrom(TextView textView) {
        if (textView == null) {
            return EMPTY;
        }

        String s = textView.getText().toString();
        return s.trim();
    }

    public static String createVariantsString(List<String> variants) {

        StringBuilder buffer = new StringBuilder();

        for (int i = 0; i < variants.size(); i++) {
            buffer.append(variants.get(i));

            if (i < variants.size() - 1) {
                buffer.append(COMMA_SEPARATOR);
            }
        }

        return buffer.toString();
    }

    public static void closeSafely(Closeable closable) {
        try {
            if (closable != null) {
                closable.close();
            }
        } catch (Exception e) {
            //do nothing
        }
    }
}
